
import ajax from '../../../until/request.js'

import { goRmd1, searchValue, getDoms, renderNav, top, lazyImg } from '../../public/js/public.js'

class Man {
  constructor() {
    // 获取搜索框
    this.search = document.querySelector("#search")
    this.searchBtn = document.querySelector("#searchBtn")

    // 获取  userInfo
    this.userInfo = JSON.parse(localStorage.getItem("userInfo"))
    this.init()

  }
  init () {
    this.getDom()
    this.getRenderData()
    this.searchValue()
    top()
    lazyImg()
    window.addEventListener("scroll", lazyImg)
    goRmd1(this.doms.home_main, this.userInfo)
  }
  getDom () {
    let doms = {
      boxClothes: ".boxClothes",
      boxShoes: ".boxShoes",
      boxLogo: ".boxLogo",
      home_main: ".home-main"
    }
    this.doms = getDoms(doms)
    console.log(this.doms)
  }
  // 请求数据
  getRenderData () {
    // 请求数据 
    ajax.getPro({
      url: 'http://localhost:8888/goods/list',
      params: {
        pagesize: 1000, // 每页多少条数据
      }
    }).then(res => {
      renderNav(JSON.parse(res).list, ["男装"], this.doms.boxClothes, 12)
      renderNav(JSON.parse(res).list, ["男鞋"], this.doms.boxShoes, 12)
      renderNav(JSON.parse(res).list, ["大牌"], this.doms.boxLogo, 12)

    })
  }

  //搜索功能
  searchValue () {
    this.searchValue = searchValue
    this.searchValue()
  }
}

let man = new Man()

export default man